#!/usr/bin/python 

import sys
import os
import re
import logging as log
from  haproxy  import haproxy as ha
from nfs import nfs_server as ns
from nfs import nfs_client as nc
from Mycat import Mycat
from ntp import ntp
from keystones import keystone
from keystones import mariaDB as my
from keystones import RabbitMQ as rabbit
from report import recorder

def main(ips_worker,dev,proxy,monitor,connector,ssl,commonPass):
    E = recorder()
    ha_operator = ha()
    ns_operator = ns()
    nc_operator = nc()
    mycat = Mycat()
    ntper = ntp()
    key = keystone()
    M = my()
    R = rabbit()
    if E.test("haproxy"):
        ha_operator.haproxy_install()
        ha_operator.haproxy_config(ips_worker,ssl)
        ha_operator.run()
        E.record("haproxy")
    if E.test("mycat"):
        mycat.operator(ips_worker,commonPass)
        E.record("mycat")
    if E.test("nfs_server"):
        ns_operator.install()
        ns_operator.ovf(proxy)
        ns_operator.init(ips_worker,dev)
        ns_operator.run()
        E.record("nfs_server")
    if E.test("nfs_client"):
        nc_operator.install(ips_worker)
        nc_operator.init(ips_worker)
#        nc_operator.config(ips_worker)
        nc_operator.run(ips_worker)
        E.record("nfs_client")
    if E.test("ntp"):
        ntper.operator(proxy,ips_worker,monitor,connector)
        E.record("ntp")
    if E.test("keystone"):
        M.operator(monitor)
        R.operator(monitor)
        key.main(monitor,monitor,dev['mongodb-device'])
        E.record("keystone")
    if connector and E.test("connector"):
        M.operator(connector)
        R.operator(connector)
        key.main(connector,connector,dev['connector-mongodb-device'])
        E.record("connector")
    return

if __name__ == "__main__":
    main(ips_worker,dev)
